#ifndef __SINGLETON_H__
#define __SINGLETON_H__

//#include <IceUtil/Mutex.h>
#include "Mutex.h"

using namespace std;

namespace MyUtil
{
template <class T> class Singleton
{
public:
	static T& instance() {
		if (!_instance) {
			IceUtil::Mutex::Lock lock(_mutex);
			if (!_instance) {
				_instance = new T;
			}
		}
		return *_instance;
	}

protected:
    Singleton() {};

	virtual ~Singleton() {
	    _instance = 0;
	}

	Singleton(const Singleton& rhs);
	Singleton& operator=(const Singleton& rhs);

protected:
	static T* _instance;
	static IceUtil::Mutex _mutex;
};

template <class T> T* Singleton<T>::_instance = 0;
template <class T> IceUtil::Mutex Singleton<T>::_mutex;


};
#endif
